﻿@model List<BenzInfo.Hockey.Grenadiers.Models.NewsFile>

@{
    ViewBag.Title = "Index";
}

<script type="text/javascript">

    $(document).ready(function () {
        $('#dialog_newsfile').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save',
                    click: function () {
                        $('form', this).submit();
                    }
                },
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });

        $('#btn_edit a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';

            $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');

            $('#dialog_newsfile').empty().load(url, function () {
                $('#dialog_newsfile').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_add a').click(function () {
            
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Models.NewsFile.AddNewsFile';

            $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');

            $('#dialog_newsfile').empty().load(url, function () {
                $('#dialog_newsfile').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
    });

</script>

<h1>@(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.News)</h1>

<div id="dialog_newsfile"></div>

@if (ViewBag.CurrentUser != null)
{
    <span id="btn_add">
        @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Models.NewsFile.AddNewsFile, "Add","NewsFiles")
    </span>
}
<table cellspacing="10px">
<tr>
    @foreach (String year in ViewBag.Years){
        bool displayYear = false;
        <td style="vertical-align:top">
            <table cellspacing="5px">
                @foreach (var item in Model){
                    if (year == item.Year)
                    {  
                        if (!displayYear){
                            <!--@(displayYear=true)--> 
                            <tr>
                                <th colspan="2">
                                    @Html.DisplayFor(modelItem => item.Year)
                                </th>
                            </tr>
                            <tr>    
                                <th>
                                    @(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Title)
                                </th>
                                @if (ViewBag.CurrentUser != null)
                                {
                                    <th>
                                        Action           
                                    </th>
                                }
                                else
                                {
                                    <th>
                                              
                                    </th>                            
                                }
                                
                            </tr> 
                        }
                    <tr>    
                        <td>
                            <a target="_blank" href="@Url.Content("~/Content/newsfiles/" + item.FileName)">@(ViewBag.Lang == "fr" ? item.TitleFR: item.TitleEN)</a>
                        </td>
                    
                    @if (ViewBag.CurrentUser != null)
                    {
                        <td>
                            <span id="btn_edit">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit, "Edit", new { id = item.Id })</span> |
                            @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete, "Delete", new { id = item.Id }, new { onclick = "return confirm('Delete?')" })
                        </td>
                    }
                    </tr>
                        
                    }
                }
            </table>
        </td>
    }
</tr>
</table>
